package com.school.controller;

import java.util.List;

import lombok.Data;

/**
 * 类名:BaseResponseVo 描述:基础返回类 创建者:冯子文 创建时间: 2016年5月9日 上午10:19:53 更新者:冯子文 更新时间:
 * 2016年5月9日 上午10:19:53
 */
@Data
public class BaseResponse {
	private String respCode;
	private String respMessage;
	private String respRemark;
	private Object data;
	private Integer total;
	private Integer maxPage;
	private List<Object> failureList;
	private List<Object> successList;

	public static final String SUCCESS = "10000000";
	public static final String FAILED = "40000000";

	public BaseResponse(String respCode, String respMessage, String respRemark) {
		this.respCode = respCode;
		this.respMessage = respMessage;
	}

	public BaseResponse(String respCode, String respMessage, String respRemark, Object data) {
		this.respCode = respCode;
		this.respMessage = respMessage;
		this.respRemark = respRemark;
		this.data = data;
	}

	public BaseResponse(String respCode, String respMessage, String respRemark, Object data, Integer total, Integer maxPage) {
		this.respCode = respCode;
		this.respMessage = respMessage;
		this.respRemark = respRemark;
		this.data = data;
		this.total = total;
		this.maxPage = maxPage;
	}

	public BaseResponse success() {
		this.respCode = "10000000";
		this.respMessage = "操作成功";
		this.respRemark = "操作成功";
		return this;
	}

	public static BaseResponse ok() {
		return new BaseResponse("10000000", "操作成功", "操作成功", null);
	}

	public static BaseResponse ok(Object data) {
		return new BaseResponse("10000000", "操作成功", "操作成功", data);
	}

	public static BaseResponse ok(Object data, Integer total, Integer maxPage) {
		return new BaseResponse("10000000", "操作成功", "操作成功", data, total, maxPage);
	}

	// 失败
	public static BaseResponse fail() {
		return new BaseResponse("40000000", "操作失败", "操作失败");
	}

	public static BaseResponse countResponse(String title, int count) {
		return count > 0 ? BaseResponse.ok(title + "成功.") : ((count < -1) ? BaseResponse.fail("传入的参数错误.") : (count == -1) ? BaseResponse.fail(title + "存在重复.") : BaseResponse.fail(title + "失败."));
	}

	public static BaseResponse fail(String respMessage) {
		return new BaseResponse("40000000", respMessage, respMessage);
	}

	public static BaseResponse fail(String respCode, String respMessage) {
		return new BaseResponse(respCode, respMessage, "操作失败");
	}

	public static BaseResponse fail(String respCode, String respMessage, String respRemark, Object data) {
		return new BaseResponse(respCode, respMessage, respRemark, data);
	}

	public static BaseResponse page(PagerInfo page, Integer pageSize) {
		return new BaseResponse("10000000", "操作成功", "操作成功", page.getList(), page.getTotal(), page.getPages());
	}

	public static BaseResponse page(PagerInfo page) {
		return page(page, 10);
	}
}
